import {
  setup,
  getRequestConfig,
  RootContainer,
  patchRoutesWithEnvProvider,
  AppEnv,
  arms,
  BrowserCheck,
  checkLoginBeforeRender,
  patchRoutesWithElementPortalProvider,
} from '@ydc/workbench-tools';
import { ThemeProvider } from '@ydc/theme';

import '@icon-park/react/styles/index.css';
import '@vendor/workbench/dist/index.css';
import '@ydc/workbench-ui/dist/index.css';
import '@ydc/web-ui/dist/index.css';
import '@ydc/workbench-tools/dist/index.css';
import '@ydc/f2ec-ydc-custom-field/dist/index.css';
import '@ydc/f2ec-ydc-excel-import/dist/index.css';
import '@/assets/styleSheet/f2eColumLayout.less';
import '@/assets/styleSheet/common.less';
import './utils/common.less';

setup({
  appEnv: APP_ENV as AppEnv,
});

if (ARMS_ENABLED) {
  arms.setup({
    pid: 'f8nmtdo7qj@399ffcda47a2b04',
    release: APP_VERSION,
    environment: APP_ENV,
  });
}

export const request = getRequestConfig({
  autoReport: ARMS_ENABLED,
});

export const rootContainer = (container: any) => {
  return (
    <RootContainer>
      <ThemeProvider root>
        <BrowserCheck />
        {container}
      </ThemeProvider>
    </RootContainer>
  );
};

export const patchRoutes = (args: any) => {
  patchRoutesWithEnvProvider(args);
  patchRoutesWithElementPortalProvider(args);
};

export function render(oldRender: any) {
  checkLoginBeforeRender(oldRender);
}
